import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class InputDialogDemo(QWidget):
    def __init__(self,parent=None):
        super(InputDialogDemo,self).__init__(parent)
        layout=QFormLayout()
        self.btn1=QPushButton("获取列表中的选项")
        self.btn1.clicked.connect(self.getItem)
        self.lin1=QLineEdit()
        layout.addRow(self.btn1,self.lin1)

        self.btn2 = QPushButton("获得字符串")
        self.btn2.clicked.connect(self.getText)
        self.lin2 = QLineEdit()

        self.btn3 = QPushButton("获得整数")
        self.btn3.clicked.connect(self.getInt)
        self.lin3 = QLineEdit()
        layout.addRow(self.btn3,self.lin3)
        layout.addRow(self.btn2, self.lin2)
        layout.addRow(self.btn2,self.lin2)
        self.setLayout(layout)
        self.setWindowTitle("InputDialog案例")

    def getItem(self):
        items=("java","python","js","C")
        item,ok=QInputDialog.getItem(self,"select input dialog","编程语言列表",items,0,False)
        if ok and item:
            self.lin1.setText(item)
    def getText(self):
        text,ok=QInputDialog.getText(self,"text input","输入姓名")
        if ok:
            self.lin2.setText(str(text))

    def getInt(self):
        num, ok = QInputDialog.getInt(self, "int input", "输入数字")
        if ok:
            self.lin3.setText(str(num))

if __name__ == '__main__':
    app=QApplication(sys.argv)
    demo=InputDialogDemo()
    demo.show()
    sys.exit(app.exec_())